package org.red5.conf;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

/**
 * @author 武玉锋
 * @Title: AsyncConfig.java
 * @Package com.anran.hgc.actions
 * @Description:   异步执行处理注解配置，可用于定时任务
 * @date 2019-05-16
 */
@Configuration
@EnableAsync
@ConfigurationProperties(prefix = "async")
public class AsyncConfig {
    /*
   此处成员变量应该使用@Value从配置中读取
    */
    @Getter
    @Setter
    private int corePoolSize ;
    @Getter
    @Setter
    private int maxPoolSize ;
    @Getter
    @Setter
    private int queueCapacity;
    @Bean(name = "smcsServertaskExecutor")
    public Executor taskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(corePoolSize);
        executor.setMaxPoolSize(maxPoolSize);
        executor.setQueueCapacity(queueCapacity);
        executor.initialize();
        return executor;
    }


}